import { BaseEntity, Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
import { LogLevel } from '../constants/log.constant';
import { HttpMethod } from '../constants/user-activity-log.constant';

@Entity('user_activity_logs')
export class UserActivityLogEntity extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column('enum', { enum: LogLevel, comment: '日志级别' })
  level: LogLevel;

  @Column('enum', { enum: HttpMethod, comment: '请求方法类型' })
  method: HttpMethod;

  @Column('uuid', { name: 'user_uuid', comment: '操作人Uuid', nullable: true })
  @Index()
  userUuid: string;

  @Column('varchar', { comment: '请求IP', nullable: true })
  @Index()
  ip: string;

  @Column('varchar', { comment: '请求URL' })
  @Index()
  url: string;

  @Column('text', { name: 'request_message', comment: '请求信息', nullable: true })
  requestMessage: string;

  @Column('int', { name: 'response_code', comment: '返回状态码' })
  responseCode: number;

  @Column('varchar', { name: 'response_message', comment: '返回信息' })
  responseMessage: string;

  @Column('int', { comment: '请求执行时间（单位：毫秒）' })
  interval: number;

  @CreateDateColumn({ type: 'timestamp', name: 'created_at', comment: '创建时间(typeorm自动生成)' })
  @Index()
  createdAt: Date;
}
